<template>
    <div>
        
        <div class="content">
            <el-form :inline="true" :model="formInline" class="demo-form-inline" >
                <el-form-item label="用户名" class="form-header">
                    <el-select
                      v-model="formInline.userId"
                      placeholder="请选择"
                      class="slect"
                      @change="getChange"
                    >
                      <el-option
                        v-for="item in userList"
                        :key="item.userId"
                        :label="item.userName"
                        :value="item.userId"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                <el-form-item label="现金余额" class="form-header">
                    <el-input v-model="formInline.cashBalance" placeholder="现金余额"></el-input>
                </el-form-item>
                <el-form-item label="优惠余额" class="form-header">
                    <el-input v-model="formInline.preferentialBalance" placeholder="优惠余额"></el-input>
                </el-form-item>
                <el-form-item label="优惠卷余额" class="form-header">
                    <el-input v-model="formInline.couponBalance" placeholder="优惠卷余额"></el-input>
                </el-form-item>
                <el-form-item label="补偿余额" class="form-header">
                    <el-input v-model="formInline.compensateBalance" placeholder="补偿余额"></el-input>
                </el-form-item>
                <el-form-item label="未开推广费用发票" class="form-header">
                  <el-input v-model="formInline.unopenedPromotionInvoice" placeholder="未开推广费用发票"></el-input>
                </el-form-item>
                <el-form-item label="已开推广费用发票" class="form-header">
                    <el-input v-model="formInline.openedPromotionInvoice" placeholder="已开推广费用发票"></el-input>
                </el-form-item>
                <el-form-item label="未开广告费用发票" class="form-header">
                    <el-input v-model="formInline.unopenedAdvertisementInvoice" placeholder="未开广告费用发票"></el-input>
                </el-form-item>
                <el-form-item label="已开广告费用发票" class="form-header">
                    <el-input v-model="formInline.openedAdvertisementInvoice" placeholder="已开广告费用发票"></el-input>
                </el-form-item>
                <el-form-item label="索要推广费用发票" class="form-header">
                    <el-input v-model="formInline.claimPromotionInvoice" placeholder="索要推广费用发票"></el-input>
                </el-form-item>
                <el-form-item label="索要广告费用发票" class="form-header">
                    <el-input v-model="formInline.claimAdvertisementInvoice" placeholder="索要广告费用发票"></el-input>
                </el-form-item>
                <el-form-item label="咨询余额" class="form-header">
                    <el-input v-model="formInline.consultBalance" placeholder="咨询余额"></el-input>
                </el-form-item>
                <el-form-item label="风险保证金余额" class="form-header">
                    <el-input v-model="formInline.riskMarginBalance" placeholder="风险保证金余额"></el-input>
                </el-form-item>
                <el-form-item label="风险保证金冻结余额" class="form-header">
                    <el-input v-model="formInline.riskMarginFreezeBalance" placeholder="风险保证金冻结余额"></el-input>
                </el-form-item>
                <el-form-item label="透支总额" class="form-header">
                    <el-input v-model="formInline.overdrawMoney" placeholder="透支总额"></el-input>
                </el-form-item>
                <el-form-item label="客户权益" class="form-header">
                    <el-input v-model="formInline.customerBenefits" placeholder="透支总额"></el-input>
                </el-form-item>
              </el-form>
              
        </div>
        <div class="queding">
            <div><el-button type="primary" v-if="!productId" @click="btnQue">确定</el-button></div>
            <div><el-button type="primary" v-if="productId" @click="btnQue2">确定</el-button></div>
          <div><el-button type="primary" plain @click="btnQuxiao">取消</el-button></div>
        </div>
    </div>
</template>
<script>
import { listAllUser } from "@/api/caiwu/zhgl";
    import {add,edit} from '@/api/caiwu/index'
export default{
    name:'zhanghugai',
    data(){
        return{
            productId:"",
            userList:[],
            value:"",
            formInline:{
                userName:"",
               userId:"",
               cashBalance:"",
               preferentialBalance:"",
               couponBalance:"",
               compensateBalance:"",
               unopenedPromotionInvoice:"",
               openedPromotionInvoice:"",
               unopenedAdvertisementInvoice:"",
               openedAdvertisementInvoice:"",
               claimPromotionInvoice:"",
               claimAdvertisementInvoice:"",
               consultBalance:"",
               riskMarginBalance:"",
               riskMarginFreezeBalance:"",
               overdrawMoney:"",
               customerBenefits:"",

            },
            options:[
                {
                    vlaue:'1',
                    label:'通过'
                },
                {
                    vlaue:'2',
                    label:'不通过'
                }
            ],
            formInline:{}
        }
    },
    
    mounted() {
        this.getList()
        if(this.objDate2){
            this.formInline=this.objDate2
            this.productId=this.objDate2.userId
        }
    },
    props:{
        objDate2: {
        type: Object,
        default: () => {},
      },
    },
    methods: {
         //修改
         btnQue2(){
            edit(this.formInline).then((res)=>{
                if(res.code ==200){
                    this.$message({
                    message: res.msg,
                    type: 'success'
                    });
                    this.btnQuxiao()
                }
            })
        },
          //确定
          btnQue(){
            add(this.formInline).then((res)=>{
                if(res.code ==200){
                    this.$message({
                    message: res.msg,
                    type: 'success'
                    });
                    this.btnQuxiao()
                }
            })
        },
         //选择
         getChange(e){
           console.log(e)
           for(let item of  this.userList){
               if(e == item.userId){
                   this.formInline.userName=item.userName
               }
           }
          
       },
        /** 查询用户列表 */
   getList() {
     listAllUser({}).then((res) => {
       res.data.forEach((item) => {
         this.userList.push({
           userName: item.userName,
           userId: item.userId,
         });
       });
     });
   },
      btnQuxiao(){
        this.$emit('quxiao')
      }
    },
}
</script>
<style scoped>
.queding{
  padding-bottom: 28px;
  text-align: center;
  display: flex;
  justify-content: space-around;
  width: 34%;
  margin: 0 auto;

}
.form-header{
    width: 430px;
    border: none;
}
.slect{
    width: 204px;
}
.content{
   width: 90%;
   margin: 0 auto;
   margin-top: 30px;
}
</style>